<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <h1 id="showTime"></h1>

    <script>

        var oShowTime = document.getElementById('showTime');

        djs();


        var t = setInterval(function () {
            // 传参数的时候可以传一个字符串
            // djs('2022-8-22 11:10:0');
            // 传参数的时候也可以传一个创建好的日期对象
            var date = new Date('2022-8-22 11:11:0');
            djs(date);
        }, 1000)




        function djs(time) {
            var t2 = new Date(time);
            var t1 = new Date();

            var gap = parseInt((t2 - t1) / 1000);

            if (gap > 0) {
                var h = parseInt(gap / 3600);
                var m = parseInt(gap % 3600 / 60);
                var s = gap % 60;

                oShowTime.innerHTML = '倒计时还有' + h + '小时' + m + '分钟' + (s < 10 ? '0' + s : s) + '秒';
            } else {
                oShowTime.innerHTML = '活动已经结束了'
                // 清除掉？？？
                clearInterval(t)
            }


        }







    </script>

</body>

</html>